//
//  SQSpecialDetailsViewController.m
//  energy
//
//  Created by 周曼迪 on 2021/7/20.
//

#import "SQSpecialDetailsViewController.h"

#import "SQSpecialDetailsModel.h"
#import "SQSpecialSubmitModel.h"

#import "SQCodeReportViewController.h"

@interface SQSpecialDetailsViewController ()<BaseTableVCInterface>
@property (strong, nonatomic) SQSpecialDetailsModel *specialDetailsModel;
@property (weak, nonatomic) IBOutlet UITextField *tf_area;
@end

@implementation SQSpecialDetailsViewController

- (void)viewDidLoad {
    self.tableViewInterface = self;
    [super viewDidLoad];
    self.navigationItem.title = @"专项检查";
    [self getSpecialDetailsData];
    
    LC_WEAK_SELF
   
    self.cellTitle = ^(int Section, int Index) {
        SQSpecialDetailsModelData * dataModel = weakSelf.specialDetailsModel.data[Section];
        SQSpecialDetailsModelContent * dataContent = dataModel.content[Index];
        SQCodeReportViewController * codeReportVC = SQCodeReportViewController.new;
        
        codeReportVC.hd_ipm = weakSelf.sa_sc;
        codeReportVC.hd_ipm_text = weakSelf.sa_scText;
        codeReportVC.strType = @"2";
        codeReportVC.hd_rt = dataModel.ci_id;
        codeReportVC.hd_rt_text = dataModel.ci_name;
        codeReportVC.hd_rp_text = dataContent.ic_name;
        codeReportVC.hd_rp = dataContent.ic_id;

        codeReportVC.codeReportBack = ^(id  _Nonnull str) {
            dataContent.sq_type = @"1";
            
            [weakSelf reloadTableView];
        };
        [weakSelf pushVC:codeReportVC];
        
    };
   
    
}


-(void)getSpecialDetailsData{
    [SQSpecialDetailsModel getDataWithParams:@{@"sa_sc":self.sa_sc} WithCallBack:^(SQSpecialDetailsModel * data) {
        
//        
        self.tf_area.text = self.sa_scText;
//        
        for (SQSpecialDetailsModelData * dataModle  in data.data) {
            for (SQSpecialDetailsModelContent *contentModel  in dataModle.content) {
                contentModel.sq_type = @"0";
            }
        }
        self.specialDetailsModel = data;
        [self reloadTableView];
    }];
}


//-(void)getSpecialData{
//    [SQCodeSpecialModel getDataWithParams:@{@"sa_sc":self.sal_sa} WithCallBack:^(SQCodeSpecialModel * data) {
//
//    }];
//}



-(NSInteger)sectionCount{
    return self.specialDetailsModel.data.count;
}

-(NSInteger)rowsCount:(NSInteger)section{
    SQSpecialDetailsModelData * dataModel = self.specialDetailsModel.data[section];
    return dataModel.content.count;
}


-(BaseModel *)modelForCell:(NSIndexPath *)indexPath{
    SQSpecialDetailsModelData * dataModel = self.specialDetailsModel.data[indexPath.section];
    return dataModel.content[indexPath.row];
}




- (NSArray<NSArray<NSString *> *> *)classArr{
    return @[@[@"SQCodeTableViewCell"]];
}

-(BaseModel *)modelForHeaderFooter:(NSInteger)section withType:(LCBaseTableVCSectionType)type{
    return  self.specialDetailsModel.data[section];
}

-(NSArray<NSString *> *)viewClassForSectionFooterHeader{
    return @[@"SQCodeView"];
}

/**确认正常*/
- (IBAction)clickNormal:(UIButton *)sender {
    
    /**方法用途：添加专项巡检记录。传参：专项申请id(srp_sa),专项检查区域id(srp_sr),人员id(srp_person_id)。成功回参：code：200。失败回参：code：0|msg。*/
    
    
    
    [SQSpecialSubmitModel getDataWithParams:@{@"srp_sa":self.self.detailsID,
                                                  @"srp_sr":self.sr_id,
                                                  @"srp_person_id":UID,
                                                
    } WithCallBack:^(SQSpecialSubmitModel * data) {
        [ CCToast showMessage:@"巡检成功"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"codeView" object:nil];
        [self.navigationController popViewControllerAnimated:YES];
        
    }];
    
    
}


- (BOOL)haveStr:(NSArray<NSString *> *)strs{
    for (NSString *key in strs) {
        if (key.length > 0) {
            return YES;
        }
    }
    return NO;
}
  



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
